<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>工厂模式</title>
  </head>
  <body>
    <script>
      class UserFactory {
        constructor(role, page) {
          this.role = role;
          this.page = page;
        }

        static useUserFactory(role) {
          switch (role) {
            case "superadmin":
              return new UserFactory("superadmin", [
                "home",
                "user-manager",
                "right-manage",
                "news-manage",
              ]);
              break;
            case "admin":
              return new UserFactory("admin", [
                "home",
                "user-manager",
                "news-manage",
              ]);
              break;
            case "editor":
              return new UserFactory("editor", ["home", "news-manage"]);
              break;
            default:
              throw Error("传入角色有误！");
          }
        }
      }

      console.log(UserFactory.useUserFactory("editor1"));
    </script>
  </body>
</html>
